package com.demo.tools

import android.app.Application
import android.content.ComponentCallbacks2
import android.util.Log
import com.bumptech.glide.Glide
import com.bumptech.glide.GlideBuilder

/**
 * @author: Liulu
 * @date: 2025/4/22
 */
class App : Application() {

    override fun onCreate() {
        super.onCreate()
        //启用Glide日志
        Glide.init(this, GlideBuilder().setLogLevel(Log.DEBUG))
        //监听内存警告，清理缓存
        //使用Android Profiler
    }

    override fun onLowMemory() {
        super.onLowMemory()
        Glide.get(this@App).clearMemory()
    }

    override fun onTrimMemory(level: Int) {
        super.onTrimMemory(level)
        Glide.get(this@App).trimMemory(level)
        if (level >= ComponentCallbacks2.TRIM_MEMORY_MODERATE) {
            Glide.get(this@App).clearMemory()
        }
    }
}